package cn.ibizlab.odoo.core.odoo_mail.service.impl;

import java.io.Serializable;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.HashMap;
import java.math.BigInteger;
import java.util.Collection;

import lombok.extern.slf4j.Slf4j;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cglib.beans.BeanCopier;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import cn.ibizlab.odoo.core.client.model.Imail_tracking_value;
import cn.ibizlab.odoo.core.odoo_mail.domain.Mail_tracking_value;
import cn.ibizlab.odoo.core.odoo_mail.filter.Mail_tracking_valueSearchContext;
import cn.ibizlab.odoo.core.odoo_mail.service.IMail_tracking_valueService;
import cn.ibizlab.odoo.util.SearchResult;
import cn.ibizlab.odoo.util.log.IBIZLog;

/**
 * 实体[邮件跟踪值] 服务对象接口实现
 */
@Slf4j
@IBIZLog
@Service
public class Mail_tracking_valueServiceImpl implements IMail_tracking_valueService {

    @Autowired
    private cn.ibizlab.odoo.core.client.service.Imail_tracking_valueClientService mail_tracking_valueClientService;

    @Override
    public boolean update(Mail_tracking_value mail_tracking_value) {
        boolean bOk = false ;
        Imail_tracking_value clientModel = this.convert2Model(mail_tracking_value,null);
        mail_tracking_valueClientService.update(clientModel) ;
        this.convert2Domain(clientModel,mail_tracking_value) ;
        bOk = true;
        return bOk ;
    }

    @Override
    public void createBatch(List<Mail_tracking_value> mail_tracking_values, int batchSize) {

                        //mail_tracking_valueClientService.createBatch(mail_tracking_values,batchSize) ;

    }

    @Override
    public boolean create(Mail_tracking_value mail_tracking_value) {
        boolean bOk = false ;
        Imail_tracking_value clientModel = this.convert2Model(mail_tracking_value,null);
        mail_tracking_valueClientService.create(clientModel) ;
        this.convert2Domain(clientModel,mail_tracking_value);
        bOk = true ;

        return bOk ;
    }

    @Override
    public void removeBatch(Collection<? extends Serializable> idList, int batchSize) {

        //mail_tracking_valueClientService.removeBatch(mail_tracking_values) ;

    }

    @Override
    public Mail_tracking_value get(Integer id) {
        Imail_tracking_value clientModel = mail_tracking_valueClientService.createModel();
        clientModel.setId(id);
        mail_tracking_valueClientService.get(clientModel) ;
        return this.convert2Domain(clientModel,null);
    }

    @Override
    public Mail_tracking_value get(Mail_tracking_value mail_tracking_value) {
        Mail_tracking_value retmail_tracking_value = this.get(mail_tracking_value.getId()) ;
    	BeanCopier copier=BeanCopier.create(retmail_tracking_value.getClass(), mail_tracking_value.getClass(), false);
        copier.copy(retmail_tracking_value, mail_tracking_value, null);
        return mail_tracking_value ;
    }

    @Override
    public void updateBatch(List<Mail_tracking_value> mail_tracking_values, int batchSize) {

        //mail_tracking_valueClientService.updateBatch(mail_tracking_values,batchSize) ;

    }

    @Override
    public boolean remove(Integer id) {
        boolean bOk = false ;
        Imail_tracking_value clientModel = mail_tracking_valueClientService.createModel();
        clientModel.setId(id);
        mail_tracking_valueClientService.remove(clientModel) ;
        bOk = true ;
        return bOk ;
    }

    /**
     * 查询集合 默认查询
     */
    @Override
    public Page<Mail_tracking_value> searchDefault(Mail_tracking_valueSearchContext context) {
        List<Mail_tracking_value> list = new ArrayList<Mail_tracking_value>();
        Page<cn.ibizlab.odoo.core.client.model.Imail_tracking_value> clientModelList = mail_tracking_valueClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Imail_tracking_value clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Mail_tracking_value>(list, context.getPageable(), clientModelList.getTotalElements());
    }


    /**
     * 根据消息查询
     */
    @Override
    public Page<Mail_tracking_value> selectByOdoo_mail_message(Integer id){
        Mail_tracking_valueSearchContext context = new Mail_tracking_valueSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(id)){
            cn.ibizlab.odoo.util.SearchFieldFilter fieldFilter=new cn.ibizlab.odoo.util.SearchFieldFilter();
            fieldFilter.setParam("id");
            fieldFilter.setCondition(cn.ibizlab.odoo.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(id);
            context.getCondition().add(fieldFilter);
        }
        List<Mail_tracking_value> list = new ArrayList<Mail_tracking_value>();
        Page<cn.ibizlab.odoo.core.client.model.Imail_tracking_value> clientModelList = mail_tracking_valueClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Imail_tracking_value clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Mail_tracking_value>(list, context.getPageable(), clientModelList.getTotalElements());

    }

    /**
     * 根据用户查询
     */
    @Override
    public Page<Mail_tracking_value> selectByOdoo_create(Integer id){
        Mail_tracking_valueSearchContext context = new Mail_tracking_valueSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(id)){
            cn.ibizlab.odoo.util.SearchFieldFilter fieldFilter=new cn.ibizlab.odoo.util.SearchFieldFilter();
            fieldFilter.setParam("id");
            fieldFilter.setCondition(cn.ibizlab.odoo.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(id);
            context.getCondition().add(fieldFilter);
        }
        List<Mail_tracking_value> list = new ArrayList<Mail_tracking_value>();
        Page<cn.ibizlab.odoo.core.client.model.Imail_tracking_value> clientModelList = mail_tracking_valueClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Imail_tracking_value clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Mail_tracking_value>(list, context.getPageable(), clientModelList.getTotalElements());

    }

    /**
     * 根据用户查询
     */
    @Override
    public Page<Mail_tracking_value> selectByOdoo_write(Integer id){
        Mail_tracking_valueSearchContext context = new Mail_tracking_valueSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(id)){
            cn.ibizlab.odoo.util.SearchFieldFilter fieldFilter=new cn.ibizlab.odoo.util.SearchFieldFilter();
            fieldFilter.setParam("id");
            fieldFilter.setCondition(cn.ibizlab.odoo.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(id);
            context.getCondition().add(fieldFilter);
        }
        List<Mail_tracking_value> list = new ArrayList<Mail_tracking_value>();
        Page<cn.ibizlab.odoo.core.client.model.Imail_tracking_value> clientModelList = mail_tracking_valueClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Imail_tracking_value clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Mail_tracking_value>(list, context.getPageable(), clientModelList.getTotalElements());

    }



    public Imail_tracking_value convert2Model(Mail_tracking_value domain , Imail_tracking_value model) {
        if(domain == null)
            return model ;
        if(model==null){
            model = mail_tracking_valueClientService.createModel() ;
        }

         if(domain.getField_descDirtyFlag())
            model.setField_desc(domain.getField_desc());
         if(domain.getOld_value_charDirtyFlag())
            model.setOld_value_char(domain.getOld_value_char());
         if(domain.getWrite_dateDirtyFlag())
            model.setWrite_date(domain.getWrite_date());
         if(domain.getNew_value_datetimeDirtyFlag())
            model.setNew_value_datetime(domain.getNew_value_datetime());
         if(domain.getOld_value_monetaryDirtyFlag())
            model.setOld_value_monetary(domain.getOld_value_monetary());
         if(domain.getNew_value_charDirtyFlag())
            model.setNew_value_char(domain.getNew_value_char());
         if(domain.getNew_value_textDirtyFlag())
            model.setNew_value_text(domain.getNew_value_text());
         if(domain.getTrack_sequenceDirtyFlag())
            model.setTrack_sequence(domain.getTrack_sequence());
         if(domain.getNew_value_monetaryDirtyFlag())
            model.setNew_value_monetary(domain.getNew_value_monetary());
         if(domain.getOld_value_datetimeDirtyFlag())
            model.setOld_value_datetime(domain.getOld_value_datetime());
         if(domain.get__last_updateDirtyFlag())
            model.set__last_update(domain.get__last_update());
         if(domain.getCreate_dateDirtyFlag())
            model.setCreate_date(domain.getCreate_date());
         if(domain.getOld_value_integerDirtyFlag())
            model.setOld_value_integer(domain.getOld_value_integer());
         if(domain.getOld_value_textDirtyFlag())
            model.setOld_value_text(domain.getOld_value_text());
         if(domain.getField_typeDirtyFlag())
            model.setField_type(domain.getField_type());
         if(domain.getNew_value_integerDirtyFlag())
            model.setNew_value_integer(domain.getNew_value_integer());
         if(domain.getDisplay_nameDirtyFlag())
            model.setDisplay_name(domain.getDisplay_name());
         if(domain.getNew_value_floatDirtyFlag())
            model.setNew_value_float(domain.getNew_value_float());
         if(domain.getIdDirtyFlag())
            model.setId(domain.getId());
         if(domain.getFieldDirtyFlag())
            model.setField(domain.getField());
         if(domain.getOld_value_floatDirtyFlag())
            model.setOld_value_float(domain.getOld_value_float());
         if(domain.getWrite_uid_textDirtyFlag())
            model.setWrite_uid_text(domain.getWrite_uid_text());
         if(domain.getCreate_uid_textDirtyFlag())
            model.setCreate_uid_text(domain.getCreate_uid_text());
         if(domain.getWrite_uidDirtyFlag())
            model.setWrite_uid(domain.getWrite_uid());
         if(domain.getCreate_uidDirtyFlag())
            model.setCreate_uid(domain.getCreate_uid());
         if(domain.getMail_message_idDirtyFlag())
            model.setMail_message_id(domain.getMail_message_id());
        return model ;
    }

    public Mail_tracking_value convert2Domain( Imail_tracking_value model ,Mail_tracking_value domain) {
        if(model == null)
            return domain ;
        if(domain == null){
            domain = new Mail_tracking_value();
        }

        if(model.getField_descDirtyFlag())
            domain.setField_desc(model.getField_desc());
        if(model.getOld_value_charDirtyFlag())
            domain.setOld_value_char(model.getOld_value_char());
        if(model.getWrite_dateDirtyFlag())
            domain.setWrite_date(model.getWrite_date());
        if(model.getNew_value_datetimeDirtyFlag())
            domain.setNew_value_datetime(model.getNew_value_datetime());
        if(model.getOld_value_monetaryDirtyFlag())
            domain.setOld_value_monetary(model.getOld_value_monetary());
        if(model.getNew_value_charDirtyFlag())
            domain.setNew_value_char(model.getNew_value_char());
        if(model.getNew_value_textDirtyFlag())
            domain.setNew_value_text(model.getNew_value_text());
        if(model.getTrack_sequenceDirtyFlag())
            domain.setTrack_sequence(model.getTrack_sequence());
        if(model.getNew_value_monetaryDirtyFlag())
            domain.setNew_value_monetary(model.getNew_value_monetary());
        if(model.getOld_value_datetimeDirtyFlag())
            domain.setOld_value_datetime(model.getOld_value_datetime());
        if(model.get__last_updateDirtyFlag())
            domain.set__last_update(model.get__last_update());
        if(model.getCreate_dateDirtyFlag())
            domain.setCreate_date(model.getCreate_date());
        if(model.getOld_value_integerDirtyFlag())
            domain.setOld_value_integer(model.getOld_value_integer());
        if(model.getOld_value_textDirtyFlag())
            domain.setOld_value_text(model.getOld_value_text());
        if(model.getField_typeDirtyFlag())
            domain.setField_type(model.getField_type());
        if(model.getNew_value_integerDirtyFlag())
            domain.setNew_value_integer(model.getNew_value_integer());
        if(model.getDisplay_nameDirtyFlag())
            domain.setDisplay_name(model.getDisplay_name());
        if(model.getNew_value_floatDirtyFlag())
            domain.setNew_value_float(model.getNew_value_float());
        if(model.getIdDirtyFlag())
            domain.setId(model.getId());
        if(model.getFieldDirtyFlag())
            domain.setField(model.getField());
        if(model.getOld_value_floatDirtyFlag())
            domain.setOld_value_float(model.getOld_value_float());
        if(model.getWrite_uid_textDirtyFlag())
            domain.setWrite_uid_text(model.getWrite_uid_text());
        if(model.getCreate_uid_textDirtyFlag())
            domain.setCreate_uid_text(model.getCreate_uid_text());
        if(model.getWrite_uidDirtyFlag())
            domain.setWrite_uid(model.getWrite_uid());
        if(model.getCreate_uidDirtyFlag())
            domain.setCreate_uid(model.getCreate_uid());
        if(model.getMail_message_idDirtyFlag())
            domain.setMail_message_id(model.getMail_message_id());
        return domain ;
    }


}
